<template>
	<view>
		<u-popup :customStyle="{width: '80%'}" :show="show" round='10' @close="show=false" closeable mode="center"
			:safeAreaInsetBottom='false'>
			<view class="popup_area">
				<view class="pop-title">审核</view>
				<u--form labelPosition="top" labelWidth="200" :model="ruleForm" :rules="rules" ref="uForm">
					<u-form-item required label="审核状态:" prop="state">
						<u-radio-group style="margin-top: 30rpx;" v-model="ruleForm.state">
							<u-radio shape="circle" name="0" label="审核通过"></u-radio>
							<u-radio style="margin-left: 20rpx;" shape="circle" name="2" label="审核驳回"></u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item v-show="ruleForm.state=='2'" required label="驳回原因:" prop="msg">
						<u--textarea :height="100" v-model="ruleForm.msg" maxlength="100" count
							placeholder="请输入驳回原因"></u--textarea>
					</u-form-item>
				</u--form>
				<view style="margin-top: 40rpx;" class="around_layout">
					<u-button shape='circle' class="sub-btn" type="error" @click="show=false">取消</u-button>
					<view style="width: 50rpx;"></view>
					<u-button shape='circle' class="sub-btn" type="primary" @click="submit">提交</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		auditCompanyAuth,
		auditProject,
		subAudit,
		progressAudit
	} from '@/utils/api.js'

	export default {
		data() {
			return {
				show: false,
				ruleForm: {
					baseIds: undefined,
					state: undefined,
					msg: undefined,
				},
				rules: {
					state: [{
						required: true,
						message: '请选择审核状态',
						trigger: 'blur',
					}, ]
				},
			};
		},
		props: {
			//1为企业审核，2为项目审核，3为子表审核，4进度审核
			type: {
				type: Number,
				default: null
			}
		},
		methods: {
			openPop(id, entryStatus) {
				if (entryStatus) {
					this.ruleForm.entryStatus = entryStatus
				}
				this.ruleForm.baseIds = [id]
				this.ruleForm.state = undefined
				this.ruleForm.msg = undefined
				this.show = true
			},
			submit() {
				this.$refs.uForm.validate().then(res => {
					if (this.ruleForm.state == '2' && !this.ruleForm.msg) {
						uni.$u.toast('请完善必填项！')
					} else {
						if (this.type == 1) {
							auditCompanyAuth(this.ruleForm).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '提交成功！',
										icon: 'success',
										duration: 2000
									})
									this.show = false
									this.$emit("popSuccess")
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}
							})
						}
						if (this.type == 2) {
							auditProject(this.ruleForm).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '提交成功！',
										icon: 'success',
										duration: 2000
									})
									this.show = false
									this.$emit("popSuccess")
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}
							})
						}
						if (this.type == 3) {
							subAudit(this.ruleForm).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '提交成功！',
										icon: 'success',
										duration: 2000
									})
									this.show = false
									this.$emit("popSuccess")
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}
							})
						}
						if (this.type == 4) {
							progressAudit(this.ruleForm).then(res => {
								if (res.code == 200) {
									uni.showToast({
										title: '提交成功！',
										icon: 'success',
										duration: 2000
									})
									this.show = false
									this.$emit("popSuccess")
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}
							})
						}
					}
				}).catch(errors => {
					uni.$u.toast('请完善必填项！')
				})
			}
		}
	}
</script>

<style lang="scss">
	.popup_area {
		padding: 30rpx;

		.pop-title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 36rpx;
			color: #303946;
			text-align: center;
		}
	}
</style>